package com.hrt.web.shoppingCar.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.ShoppingCar;
import com.hrt.web.shoppingCar.dao.ShoppingCarDao;
import com.hrt.web.shoppingCar.service.ShoppingCarService;
@Service
@Transactional
public class ShoppingCarServiceImpl implements ShoppingCarService{
	@Autowired
	private ShoppingCarDao shopppingCarDao;
	@Override
	public Long totalCount() {
		return shopppingCarDao.totalCount();
	}

	@Override
	public void deleteById(Long[] ids) throws Exception {
		List<ShoppingCar> delResult = shopppingCarDao.getByIds(ids);
		for (ShoppingCar  sc: delResult) {
			sc.setIsdelete(new Integer(1));
			this.shopppingCarDao.updateEntity(sc);
		}
		
	}

	@Override
	public void saveCar(ShoppingCar shoppingCar) throws Exception {
		shopppingCarDao.saveEntity(shoppingCar);
		
	}

	@Override
	public List queryByPage(int pageIndex, int pageSize) {
		return shopppingCarDao.queryByPage(pageIndex, pageSize);
	}

	@Override
	public void updateCar(ShoppingCar shoppingCar) {
		shopppingCarDao.updateEntity(shoppingCar);
		
	}

	@Override
	public Timestamp getDate() {
		return shopppingCarDao.getDate();
	}

	@Override
	public Long getCarByMemberId(Long memberId) {
		return shopppingCarDao.getCarByMemberId(memberId);
	}

	@Override
	public List<ShoppingCar> getShoppingCarByMemberId(Long memberId) {
		return shopppingCarDao.getShoppingCarByMemberId(memberId);
	}

	@Override
	public void deleteByCarId(Long id) {
		ShoppingCar car = shopppingCarDao.getById(id);
		car.setIsdelete(1);
		shopppingCarDao.updateEntity(car);
		
	}

	@Override
	public ShoppingCar getCarById(Long CarId) {
		return shopppingCarDao.getById(CarId);
	}

}
